﻿/*
' DotNetNuke® - http://www.dotnetnuke.com
' Copyright (c) 2002-2009
' by DotNetNuke Corporation
'
' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
' documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
' the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
' to permit persons to whom the Software is furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in all copies or substantial portions 
' of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
' DEALINGS IN THE SOFTWARE.
*/

using MbUnit.Framework;
using WatiN.Core;
using DotNetNuke.Tests.UI.WatiN.Common;
using DotNetNuke.Tests.UI.WatiN.Common.WatiNObjects;

namespace DotNetNuke.Tests.UI.WatiN.SiteTests
{
    [TestFixture]
    public class ControlPanelTests : STBase
    {
        #region Test Setup and TearDown

        [SetUp]
        public void SetUp()
        {
            SetUpTest();
        }

        [TearDown]
        public void TearDown()
        {
            TearDownTest();
        }

        #endregion

        #region Tests

        [Test]
        public void Changing_Mode_To_View()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");
            HostSettingsPage hostSettings = new HostSettingsPage(homePage);

            hostSettings.HostEmailTextField.Value = TestUsers.Host.Email;
            //hostSettings.OtherSettingsExpandButton.Click();
            //hostSettings.ControlPanelStyleSelectList.Select("ICONBAR");
            //hostSettings.UpdateLink.ClickNoWait();
            hostSettings.UpdateControlPanelStyle("ICONBAR");
            System.Threading.Thread.Sleep(1000);

            ieInstance.GoTo(SiteURL + "/Home.aspx");
            
            //Act 
            System.Threading.Thread.Sleep(1000);
            ControlPanel controlPanel = new ControlPanel(homePage);
            controlPanel.ViewRadioButton.Checked = true;

            //Assert 
            System.Threading.Thread.Sleep(1000);
            ModulePage modulePage = new ModulePage(homePage);
            Assert.IsFalse(modulePage.EditModuleContentLink.Exists);
            Assert.IsFalse(modulePage.ModuleActionMenuImage.Exists);

        }

        [Test]
        public void Changing_Mode_To_Edit()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");
            HostSettingsPage hostSettings = new HostSettingsPage(homePage);

            hostSettings.HostEmailTextField.Value = TestUsers.Host.Email;
            //hostSettings.OtherSettingsExpandButton.Click();
            //hostSettings.ControlPanelStyleSelectList.Select("ICONBAR");
            //hostSettings.UpdateLink.ClickNoWait();
            hostSettings.UpdateControlPanelStyle("ICONBAR");
            System.Threading.Thread.Sleep(1000);

            //Act 
            System.Threading.Thread.Sleep(1000);
            ControlPanel controlPanel = new ControlPanel(homePage);
            controlPanel.ViewRadioButton.Checked = true;
            System.Threading.Thread.Sleep(2000);
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            controlPanel.EditRadioButton.Checked = true;

            //Assert 
            System.Threading.Thread.Sleep(1000);
            ModulePage modulePage = new ModulePage(homePage);
            Assert.IsTrue(modulePage.ActionMenuBody.Exists);
            Assert.IsTrue(modulePage.EditModuleContentLink.Exists);
        }

        [Test]
        public void Changing_Mode_To_Layout()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");
            HostSettingsPage hostSettings = new HostSettingsPage(homePage);

            hostSettings.HostEmailTextField.Value = TestUsers.Host.Email;
            //hostSettings.OtherSettingsExpandButton.Click();
            //hostSettings.ControlPanelStyleSelectList.Select("ICONBAR");
            //hostSettings.UpdateLink.ClickNoWait();
            hostSettings.UpdateControlPanelStyle("ICONBAR");
            System.Threading.Thread.Sleep(1000);

            //Act 
            System.Threading.Thread.Sleep(1000);
            ControlPanel controlPanel = new ControlPanel(homePage);
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            controlPanel.LayoutRadioButton.Checked = true;

            //Assert 
            System.Threading.Thread.Sleep(1000);
            ModulePage modulePage = new ModulePage(homePage);
            Assert.IsFalse(modulePage.EditModuleContentLink.Exists);
            Assert.IsTrue(modulePage.ActionMenuBody.Exists);
            //Assert.IsTrue(homePage.ContentDiv.InnerHtml.Contains("TopPane"));
            Assert.IsTrue(homePage.ContentDiv.InnerHtml.Contains("RightPane"));
            Assert.IsTrue(homePage.ContentDiv.InnerHtml.Contains("LeftPane"));
            Assert.IsTrue(homePage.ContentDiv.InnerHtml.Contains("ContentPane"));
            Assert.IsTrue(homePage.ContentDiv.InnerHtml.Contains("BottomPane"));
        }

        [Test]
        public void Verify_Site_Link()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");
            HostSettingsPage hostSettings = new HostSettingsPage(homePage);

            hostSettings.HostEmailTextField.Value = TestUsers.Host.Email;
            //hostSettings.OtherSettingsExpandButton.Click();
            //hostSettings.ControlPanelStyleSelectList.Select("ICONBAR");
            //hostSettings.UpdateLink.ClickNoWait();
            hostSettings.UpdateControlPanelStyle("ICONBAR");
            System.Threading.Thread.Sleep(1000);

            //Act 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            ControlPanel controlPanel = new ControlPanel(homePage);
            controlPanel.SiteSettingsLink.Click();

            //Assert 
            SiteMenu menu = new SiteMenu(homePage);
            Assert.IsTrue(homePage.ModuleTitleSpans.Count == 1);
            Assert.IsTrue(homePage.ModuleTitleSpan.InnerHtml.Contains("Site Settings"));
            Assert.IsTrue(menu.BreadCrumbSpan.InnerHtml.Contains("Site Settings"));
        }

        [Test]
        public void Verify_Users_Link()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");
            HostSettingsPage hostSettings = new HostSettingsPage(homePage);

            hostSettings.HostEmailTextField.Value = TestUsers.Host.Email;
            //hostSettings.OtherSettingsExpandButton.Click();
            //hostSettings.ControlPanelStyleSelectList.Select("ICONBAR");
            //hostSettings.UpdateLink.ClickNoWait();
            hostSettings.UpdateControlPanelStyle("ICONBAR");
            System.Threading.Thread.Sleep(1000);

            //Act 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            ControlPanel controlPanel = new ControlPanel(homePage);
            controlPanel.UsersLink.ClickNoWait();
            System.Threading.Thread.Sleep(1500);

            //Assert 
            SiteMenu menu = new SiteMenu(homePage);
            Assert.IsTrue(homePage.ModuleTitleSpans.Count == 1);
            Assert.IsTrue(homePage.ModuleTitleSpan.InnerHtml.Contains("User Accounts"));
            Assert.IsTrue(menu.BreadCrumbSpan.InnerHtml.Contains("User Accounts"));
        }

        [Test]
        public void Verify_Roles_Link()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");
            HostSettingsPage hostSettings = new HostSettingsPage(homePage);

            hostSettings.HostEmailTextField.Value = TestUsers.Host.Email;
            //hostSettings.OtherSettingsExpandButton.Click();
            //hostSettings.ControlPanelStyleSelectList.Select("ICONBAR");
            //hostSettings.UpdateLink.ClickNoWait();
            hostSettings.UpdateControlPanelStyle("ICONBAR");
            System.Threading.Thread.Sleep(1000);

            //Act 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            ControlPanel controlPanel = new ControlPanel(homePage);
            controlPanel.RolesLink.Click();

            //Assert 
            SiteMenu menu = new SiteMenu(homePage);
            Assert.IsTrue(homePage.ModuleTitleSpans.Count == 1);
            Assert.IsTrue(homePage.ModuleTitleSpan.InnerHtml.Contains("Security Roles"));
            Assert.IsTrue(menu.BreadCrumbSpan.InnerHtml.Contains("Security Roles"));
        }

        [Test]
        public void Verify_Files_Link()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");
            HostSettingsPage hostSettings = new HostSettingsPage(homePage);

            hostSettings.HostEmailTextField.Value = TestUsers.Host.Email;
            //hostSettings.OtherSettingsExpandButton.Click();
            //hostSettings.ControlPanelStyleSelectList.Select("ICONBAR");
            //hostSettings.UpdateLink.ClickNoWait();
            hostSettings.UpdateControlPanelStyle("ICONBAR");
            System.Threading.Thread.Sleep(1000);

            //Act 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            ControlPanel controlPanel = new ControlPanel(homePage);
            controlPanel.FilesLink.Click();

            //Assert 
            SiteMenu menu = new SiteMenu(homePage);
            Assert.IsTrue(homePage.ModuleTitleSpans.Count == 1);
            Assert.IsTrue(homePage.ModuleTitleSpan.InnerHtml.Contains("File Manager"));
            Assert.IsTrue(menu.BreadCrumbSpan.InnerHtml.Contains("File Manager"));
        }

        [Test]
        public void Verify_Help_Link()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");
            HostSettingsPage hostSettings = new HostSettingsPage(homePage);

            hostSettings.HostEmailTextField.Value = TestUsers.Host.Email;
            //hostSettings.OtherSettingsExpandButton.Click();
            //hostSettings.ControlPanelStyleSelectList.Select("ICONBAR");
            //hostSettings.UpdateLink.ClickNoWait();
            hostSettings.UpdateControlPanelStyle("ICONBAR");
            System.Threading.Thread.Sleep(1000);

            //Act 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            ControlPanel controlPanel = new ControlPanel(homePage);
            controlPanel.HelpLink.Click();

            //Assert 
            System.Threading.Thread.Sleep(5000);
            IE popUpWindow = IE.AttachTo<IE>(Find.ByUrl(s => s.StartsWith("http://www.dotnetnuke.com")));
            Assert.IsTrue(popUpWindow.Title.Contains("DotNetNuke > Resources > Support > Online Manual"));
            popUpWindow.Close();
        }

        [Test]
        public void Verify_Extensions_Link()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");
            System.Threading.Thread.Sleep(1500);
            HostSettingsPage hostSettings = new HostSettingsPage(homePage);

            hostSettings.HostEmailTextField.Value = TestUsers.Host.Email;
            //hostSettings.OtherSettingsExpandButton.Click();
            //hostSettings.ControlPanelStyleSelectList.Select("ICONBAR");
            //hostSettings.UpdateLink.ClickNoWait();
            hostSettings.UpdateControlPanelStyle("ICONBAR");
            System.Threading.Thread.Sleep(1000);

            //Act 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            ControlPanel controlPanel = new ControlPanel(homePage);
            controlPanel.ExtensionsLink.Click();

            //Assert 
            System.Threading.Thread.Sleep(1500);
            SiteMenu menu = new SiteMenu(homePage);
            Assert.IsTrue(homePage.ModuleTitleSpans.Count == 1);
            Assert.IsTrue(homePage.ModuleTitleSpan.InnerHtml.Contains("Extensions"));
            Assert.AreEqual("AdminExtensions", menu.BreadCrumbSpan.Text);
        }


        [Test]
        public void Show_Control_Panel()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");
            System.Threading.Thread.Sleep(1500);
            HostSettingsPage hostSettings = new HostSettingsPage(homePage);

            hostSettings.HostEmailTextField.Value = TestUsers.Host.Email;
            //hostSettings.OtherSettingsExpandButton.Click();
            //hostSettings.ControlPanelStyleSelectList.Select("ICONBAR");
            //hostSettings.UpdateLink.ClickNoWait();
            hostSettings.UpdateControlPanelStyle("ICONBAR");
            System.Threading.Thread.Sleep(1000);

            //Act 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            ControlPanel controlPanel = new ControlPanel(homePage);
            controlPanel.MinimiseControlPanelImage.ClickNoWait();
            System.Threading.Thread.Sleep(1000);

            //Assert 
            Assert.IsTrue(controlPanel.MinimiseControlPanelImage.Src.Contains("expand.gif"));
            Assert.IsFalse(controlPanel.MinimiseControlPanelImage.Src.Contains("collapse.gif"));

            controlPanel.MinimiseControlPanelImage.ClickNoWait();
            System.Threading.Thread.Sleep(1000);
            Assert.IsFalse(controlPanel.MinimiseControlPanelImage.Src.Contains("expand.gif"));
            Assert.IsTrue(controlPanel.MinimiseControlPanelImage.Src.Contains("collapse.gif"));

        }

        #endregion
    }
}

